import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:search_people/utils/fun_util.dart';

import '../../../../utils/component/component.dart';
import '../../../../utils/util.dart';
import 'controller.dart';

class SetupPage extends GetView<SetupController> {
  const SetupPage({Key? key}) : super(key: key);

  Widget _getItem(
      {required String title,
      required String content,
      required VoidCallback onTap}) {
    return TitleContentItemView(
        padding: EdgeInsets.symmetric(horizontal: 12.r),
        backgroundColor: Colors.white,
        fontSize: 16.sp,
        onTap: onTap,
        title: title,
        content: content);
  }

  Widget _getLine() {
    return separatorLine(indent: 12.r, endIndent: 12.r);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: detailAppBar(context, title: '设置'),
      body: ListView(
        children: [
          Obx(() => TitleContentItemView(
                padding: EdgeInsets.symmetric(horizontal: 12.r),
                backgroundColor: Colors.white,
                fontSize: 16.sp,
                title: '设置头像',
                height: 80.r,
                onTap: controller.actionAvater,
                contentWidget: loadAvater(
                    url: controller.userCtrl.state.userObs.value.headImgUrl,
                    size: 50.w),
              )),
          _getLine(),
          Obx(
            () => _getItem(
                title: '昵称',
                content: controller.userCtrl.state.userObs.value.nickName ?? '',
                onTap: controller.actionNickName),
          ),
          _getLine(),
          TitleContentItemView(
            padding: EdgeInsets.symmetric(horizontal: 12.r),
            backgroundColor: Colors.white,
            fontSize: 16.sp,
            title: '用户名',
            content: controller.userCtrl.state.user?.userName ?? '',
            contentStyle:
                TextStyle(color: const Color(0xff333333), fontSize: 15.sp),
            hasArrow: false,
          ),
          _getLine(),
          Obx(
            () => _getItem(
                title: '手机号',
                content: controller.state.phone.value.phone,
                onTap: controller.actionPhone),
          ),
          SizedBox(
            height: 10.r,
          ),
          _getItem(
              title: '登录密码设置',
              content: '去设置',
              onTap: controller.actionLoginPwd),
          SizedBox(
            height: 10.r,
          ),
          Obx(
            () => _getItem(
                title: '清除缓存',
                content: controller.state.cacheSize.value,
                onTap: controller.actionClearCache),
          ),
          _getLine(),
          Obx(
            () => _getItem(
                title: '关于我们',
                content: controller.state.version.value,
                onTap: controller.actionAboutUs),
          )
        ],
      ),
      bottomNavigationBar: Padding(
        padding: EdgeInsets.symmetric(
            horizontal: 31.r, vertical: ScreenUtil().bottomBarHeight + 15.r),
        child: ExpandedButton(
          text: '退出登录',
          backgroundColor: Colors.white,
          textColor: Colors.grey[600],
          onPressed: controller.actionLoginOut,
        ),
      ),
    );
  }
}
